package banwood.com.xiongfasy.activity;

import android.app.ActionBar;
import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.json.JSONException;
import org.json.JSONObject;

import banwood.com.xiongfasy.BASE.BaseActivity;
import banwood.com.xiongfasy.BASE.GetMessage;
import banwood.com.xiongfasy.R;
import butterknife.BindView;
import butterknife.OnClick;
import cn.weipass.pos.sdk.Weipos;
import cn.weipass.pos.sdk.impl.WeiposImpl;

/*
 * 
 * 主界面
 * */
public class HomeActivity extends BaseActivity {
    private static String TAG="HomeActivity";
    @BindView(R.id.linear_shoukuai)
    LinearLayout linearShoukuai;
    @BindView(R.id.linear_bill)
    LinearLayout linearBill;
    @BindView(R.id.main_search)
    LinearLayout mainSearch;
    @BindView(R.id.linear_tuikuai)
    LinearLayout linearTuikuai;
    @BindView(R.id.version_hao)
    TextView versionHao;
    private ActionBar actionBar;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        actionBar = getActionBar();
        actionBar.hide();
        versionHao.setText(GetMessage.getVersion(HomeActivity.this));
    }

    @Override
    protected void initData() {

        MyApplication.setEnHao("00000000");
       WeiposImpl.as().init(HomeActivity.this, new Weipos.OnInitListener() {

           @Override
           public void onInitOk() {
               String deviceInfo = WeiposImpl.as().getDeviceInfo();
                   if (deviceInfo!=null) {
                       try {
                           JSONObject deviceJson = new JSONObject(deviceInfo);
                           if (deviceJson.has("en")) {
                               String en = deviceJson.getString("en");
                               en=en.replaceAll(" ","");
                               MyApplication.setEnHao(en);
                           }
                       } catch (JSONException e) {
                           e.printStackTrace();
                       }
                   }
           }

           @Override
           public void onError(String s) {
           }

           @Override
           public void onDestroy() {
           }
       });

    }

    @OnClick({R.id.linear_bill, R.id.linear_shoukuai, R.id.linear_tuikuai, R.id.main_search})
    public void mainOnclick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.linear_shoukuai:
                intent = new Intent(HomeActivity.this, ShouKuaiActivity.class);
                startActivity(intent);
                break;
            case R.id.linear_bill:
                intent = new Intent(HomeActivity.this, BillActivity.class);
                startActivity(intent);
                break;

            case R.id.main_search:
                intent = new Intent(HomeActivity.this, InquiryActivity.class);
                startActivity(intent);
                break;
            case R.id.linear_tuikuai:
                intent = new Intent(HomeActivity.this, TuiKuaiActivity.class);
                startActivity(intent);
                break;
        }

    }



}
